package com.wq.httpclientcore.entities.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.wq.httpclientcore.handle.MapTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;

@Getter
@Setter
@TableName(value = "api_config", autoResultMap = true)
@Schema(name = "ApiConfig", description = "API 配置信息")
public class ApiConfig implements Serializable {

    @TableId(value = "id")
    @Schema(description = "API 配置的唯一标识", example = "1")
    private Long id;

    @TableField("name")
    @Schema(description = "API 配置的名称", example = "用户信息查询 API")
    private String name;

    @TableField("base_url")
    @Schema(description = "API 的基础 URL", example = "https://api.example.com")
    private String baseUrl;

    @TableField("path")
    @Schema(description = "API 的路径", example = "/users")
    private String path;

    @TableField("method")
    @Schema(description = "API 的请求方法", example = "GET")
    private String method;

    @TableField(value = "request_params", typeHandler = MapTypeHandler.class)
    @Schema(description = "API 的请求参数", example = "{\"param1\": \"value1\", \"param2\": \"value2\"}")
    private Map<String, Object> requestParams;

    @TableField(value = "request_headers", typeHandler = MapTypeHandler.class)
    @Schema(description = "API 的请求头", example = "{\"Content-Type\": \"application/json\"}")
    private Map<String, Object> requestHeaders;

    @TableField(value = "request_body", typeHandler = MapTypeHandler.class)
    @Schema(description = "API 的请求体", example = "{\"key\": \"value\"}")
    private Map<String, Object> requestBody;

    @TableField("response_type")
    @Schema(description = "API 的响应类型", example = "JSON")
    private String responseType;

    @TableField("auth_config_id")
    @Schema(description = "关联的鉴权配置 ID", example = "1")
    private Long authConfigId;

    @TableField(exist = false)
    @Schema(description = "关联的鉴权配置", example = "权限认证")
    private AuthConfig authConfig;

    @TableField("enabled")
    @Schema(description = "API 是否启用", example = "true")
    private Boolean enabled;

    @TableField("created_at")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8", shape = JsonFormat.Shape.STRING)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @Schema(description = "API 配置的创建时间", example = "2025-03-10 15:41:09")
    private LocalDateTime createdAt;

    @TableField("updated_at")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8", shape = JsonFormat.Shape.STRING)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @Schema(description = "API 配置的更新时间", example = "2025-03-10 15:41:09")
    private LocalDateTime updatedAt;
}